#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int minimumDifference(vector<int>& nums, int k) {
    sort(nums.begin(), nums.end());
    int n = nums.size();

    int minDis = 2147483647;
    for(int i=k-1;i<n;i++){
        minDis = min(minDis, nums[i]-nums[i-k+1]);
    }
    return minDis;
}

int main(){
    cout << "hello world" << endl;
    vector<int> nums{9,4,1,7};
    cout << minimumDifference(nums, 2);
}